package codepulse.blogmoon.cn.system.controller.admin;

import codepulse.blogmoon.cn.common.entity.PageResult;
import codepulse.blogmoon.cn.common.entity.Result;
import codepulse.blogmoon.cn.common.utils.PageUtil;
import codepulse.blogmoon.cn.system.dto.admin.AdminAcctInfoDTO;
import codepulse.blogmoon.cn.system.dto.admin.QueryAdminUserReq;
import codepulse.blogmoon.cn.system.entity.SysAdminAcctInfo;
import codepulse.blogmoon.cn.system.service.SysAdminAcctInfoService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/user")
public class AdminAccountController {


    @Resource
    private SysAdminAcctInfoService sysAdminAcctInfoService;

    @PostMapping("/page")
    public Result page(@RequestBody QueryAdminUserReq req) {
        PageResult<AdminAcctInfoDTO> page = sysAdminAcctInfoService.pageAcctInfo(req);
        return Result.success(page);
    }


    @PostMapping("/create")
    public Result save(@RequestBody AdminAcctInfoDTO dto) {
        sysAdminAcctInfoService.create(dto);
        return Result.success();
    }


    @PostMapping("/modify")
    public Result modify(@RequestBody AdminAcctInfoDTO dto) {
        sysAdminAcctInfoService.modify(dto);
        return Result.success();
    }

    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Long id) {
        sysAdminAcctInfoService.removeAcct(id);
        return Result.success();
    }

    @GetMapping("/detail/{id}")
    public Result detail(@PathVariable("id") Long id) {
        AdminAcctInfoDTO adminAcctInfoDTO = sysAdminAcctInfoService.detail(id);
        return Result.success(adminAcctInfoDTO);
    }


}
